package com.ruoyi.controller.middlesign.timing;

import com.alibaba.fastjson.JSON;
import com.ruoyi.service.middlesign.MiddlesignDayService;
import com.ruoyi.service.middlesign.MiddlesignService;
import com.ruoyi.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author zeo
 * @explain 每日发送
 * @date 2021/3/16 16:10
 */
@Component
public class EveryDay {

    @Autowired
    MiddlesignDayService middlesignDayService;

    @Autowired
    MiddlesignService middlesignService;

    public void day() {
        //清空所有日推送表
        middlesignDayService.emptyAccountsDay();
        middlesignDayService.emptyPaymentDay();
        middlesignDayService.emptyReconciliationDay();

        List<Map<String, Object>> mapList = middlesignDayService.findMiddlesCreditDaySendList();
        for (Map map : mapList) {
            String credit_name = map.get("CREDITNAME").toString();
            String credit_code = map.get("creditCode").toString();
            String hxqy_name = map.get("hxqyName").toString();
            String hxqy_code = map.get("hxqyCode").toString();

            //B2804
            middlesignDayService.insertStockDataAccounts(map);
            List<Map<String,Object>> mapList1 = middlesignDayService.findStockDataAccounts(map);
            String jsonString = JSON.toJSONString(mapList1);
            BaseResult baseResult = middlesignService.accountsPushData(jsonString,credit_code,credit_name,hxqy_code,"day");
            System.out.println(baseResult);

            //B2805
            middlesignDayService.insertStockDataPayment(map);
            List<Map<String,Object>> mapList2 = middlesignDayService.findStockDataPayment(map);
            String jsonString1 = JSON.toJSONString(mapList2);
            BaseResult baseResult1 = middlesignService.paymentPushData(jsonString1,credit_code,credit_name,hxqy_code,"day");
            System.out.println(baseResult1);

            //B2806
            middlesignService.insertStockSupplierAccount(credit_name);
            List<Map<String,Object>> mapList3 = middlesignDayService.findStockSupplierAccount(map);
            String jsonString2 = JSON.toJSONString(mapList3);
            BaseResult baseResult2 = middlesignService.supplierPush(jsonString2,credit_code,hxqy_code,"day");
            System.out.println(baseResult2);

            //B2807
            middlesignDayService.insertReconciliationData(map);
            List<Map<String,Object>> mapList4 = middlesignDayService.findReconciliationData(map);
            String jsonString3 = JSON.toJSONString(mapList4);
            BaseResult baseResult3 = middlesignService.reconciliationDataPush(jsonString3,credit_code,credit_name,hxqy_code,"day");
            System.out.println(baseResult3);
        }
    }
}
